package com.felix.ocoupon.converter;

import com.alibaba.fastjson.JSON;
import com.felix.ocoupon.constant.OcouponCategory;
import com.felix.ocoupon.vo.TemplateRule;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * @author hsufelix
 * @email hsufelix@yeah.net
 * @Date 2020/11/12
 * RuleConverter
 * 枚举转换器
 */
@Converter
public class RuleConverter implements
        AttributeConverter<TemplateRule, String> {

    @Override
    public String convertToDatabaseColumn(TemplateRule rule) {
        return JSON.toJSONString(rule);
    }

    @Override
    public TemplateRule convertToEntityAttribute(String rule) {
        return JSON.parseObject(rule, TemplateRule.class);
    }
}
